import React, { useRef } from 'react'
import Child from './Child'

export default function Parent() {
  //1. 创建 ref 容器
  let ref = useRef();
  return (
    <div>
      <button onClick={() => {
        ref.current.incre();
      }}>增加</button>
      <button onClick={() => {
        ref.current.decre();
      }}>减少</button>
      <hr />
      {/* 2. 设置子组件标签的 ref 属性 */}
      <Child ref={ref} />
    </div>
  )
}
